//
//  ZH_MineTopTableViewCell.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/10/19.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_MineTopTableViewCell.h"
@interface ZH_MineTopTableViewCell()
@property (nonatomic,weak)UIView *bgView;
@property (nonatomic,weak)UIView *bgViews;
@property (nonatomic,weak)UIImageView *photoImage;
@property (nonatomic,weak)UILabel *leftLabel;
@property (nonatomic,weak)UILabel *rightLabel;
@property (nonatomic,weak)UIView *scoBgView;
@property (nonatomic,weak)UILabel *titleLabel;
@property (nonatomic,weak)UIView *lineView;
@property (nonatomic,weak)UILabel *contentLabel;
@property (nonatomic,weak)UIImageView *images;
@property (nonatomic,weak)UILabel *titleLabels;
@property (nonatomic,weak)UIButton *leftButton;
@property (nonatomic,weak)UIButton *rightButton;
@end
@implementation ZH_MineTopTableViewCell

///创建
+(instancetype)cellWithTableView:(UITableView*)tableView
{
    static NSString *ID = @"ZH_MineTopTableViewCell";
    ZH_MineTopTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[ZH_MineTopTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
///初始化
-(void)initDefault
{
    [self unShowClickEffect];
//    self.bottomShortLineImage.hidden = NO;
}
- (void)loadSubviewConstraints{
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.contentView);
        make.height.mas_equalTo(FITSCALE(230));
//        make.bottom.equalTo(self.contentView);
    }];
    [self.bgViews mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(89));
        make.left.equalTo(self.contentView).offset(FITSCALE(22));
        make.right.equalTo(self.contentView).offset(FITSCALE(-22));
        make.height.mas_equalTo(FITSCALE(98));
    }];
    [self.photoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(64));
        make.centerX.equalTo(self.contentView);
        make.height.mas_equalTo(FITSCALE(50));
        make.width.mas_equalTo(FITSCALE(50));
    }];
    [self.titleLabels mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.photoImage.mas_bottom).offset(FITSCALE(10));
    }];
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgViews).offset(FITSCALE(67));
        make.left.equalTo(self.bgViews).offset(FITSCALE(41));
    }];
    [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.leftLabel);
    }];
    [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.leftLabel);
        make.right.equalTo(self.bgViews).offset(FITSCALE(-41));
    }];
    [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.rightLabel);
    }];
    [self.scoBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgViews.mas_bottom).offset(FITSCALE(20));
        make.left.equalTo(self.contentView).offset(FITSCALE(12));
        make.right.equalTo(self.contentView).offset(FITSCALE(-12));
        make.height.mas_equalTo(FITSCALE(49));
        make.bottom.equalTo(self.contentView);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.scoBgView);
        make.left.equalTo(self.scoBgView).offset(FITSCALE(21));
//        make.width.mas_equalTo(FITSCALE(34));
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.scoBgView);
        make.height.mas_equalTo(FITSCALE(40));
        make.left.equalTo(self.titleLabel.mas_right).offset(FITSCALE(21));
        make.width.mas_equalTo(FITSCALE(2));
    }];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.scoBgView);
        make.left.equalTo(self.lineView.mas_right).offset(FITSCALE(7));
    }];
    [self.images mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.scoBgView);
        make.right.equalTo(self.scoBgView).offset(FITSCALE(-10));
        make.width.mas_equalTo(FITSCALE(64));
        make.height.mas_equalTo(FITSCALE(40));
    }];
}
- (void)updataUI:(NSDictionary *)data{
    if (data) {
        [self.photoImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,data[@"head"]]]];
        self.titleLabels.text = [NSString stringWithFormat:@"%@",data[@"nickname"]];
        self.leftLabel.text = [NSString stringWithFormat:@"关注教师:%@",data[@"teacher_attention_num"]];
        self.rightLabel.text = [NSString stringWithFormat:@"关注机构:%@",data[@"mechanism_attention_num"]];
    }
}
- (void)button:(UIButton *)btn{
    if (self.onButtonClick) {
        self.onButtonClick();
    }
}
#pragma mark - getter,setter
- (UIView *)bgView{
    if (!_bgView) {
        UIView *view = [UIView createViewWithBackgroundColor:[UIColor colorWithHexString:@"#00C9AE"]];
        [self.contentView addSubview:_bgView = view];
    }
    return _bgView;
}
- (UIView *)bgViews{
    if (!_bgViews) {
        UIView *view = [UIView createViewWithBackgroundColor:kFontColorWhite];
        view.layer.cornerRadius = FITSCALE(3);
        view.layer.masksToBounds = YES;
        view.clipsToBounds = YES;
        view.alpha = 0.8;
        [self.contentView addSubview:_bgViews = view];
    }
    return _bgViews;
}
- (UIImageView *)photoImage{
    if (!_photoImage) {
        UIImageView *image = [UIImageView createImageViewWithName:@""];
        image.backgroundColor = kFontColorRed;
        image.layer.cornerRadius = FITSCALE(25);
        image.layer.masksToBounds = YES;
        image.clipsToBounds = YES;
        [self.contentView addSubview:_photoImage = image];
    }
    return _photoImage;
}
- (UILabel *)leftLabel{
    if (!_leftLabel) {
        UILabel *label = [UILabel createLabelWithText:@"关注教师:55" font:kFontSize_28];
        [self.contentView addSubview:_leftLabel = label];
    }
    return _leftLabel;
}
- (UILabel *)rightLabel{
    if (!_rightLabel) {
        UILabel *label = [UILabel createLabelWithText:@"关注机构:55" font:kFontSize_28];
        label.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_rightLabel = label];
    }
    return _rightLabel;
}
- (UIView *)scoBgView{
    if (!_scoBgView) {
        UIView *view = [UIView createViewWithBackgroundColor:kFontColorWhite];
        view.layer.cornerRadius = FITSCALE(3);
        view.layer.masksToBounds = YES;
        view.clipsToBounds = YES;
        [self.contentView addSubview:_scoBgView = view];
    }
    return _scoBgView;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [UILabel createLabelWithText:@"公告" font:kFontSize_34];
        label.font = [UIFont boldSystemFontOfSize:17];
        [self.contentView addSubview:_titleLabel = label];
    }
    return _titleLabel;
}
- (UILabel *)titleLabels{
    if (!_titleLabels) {
        UILabel *label = [UILabel createLabelWithText:@"立即登录" font:kFontSize_28];
        [self.contentView addSubview:_titleLabels = label];
    }
    return _titleLabels;
}
- (UIView *)lineView{
    if (!_lineView) {
        UIView *lineView = [UIView createViewWithBackgroundColor:[UIColor colorWithHexString:@"#DFDFDF"]];
        [self.contentView addSubview:_lineView = lineView];
    }
    return _lineView;
}
- (UILabel *)contentLabel{
    if (!_contentLabel) {
        UILabel *label = [UILabel createLabelWithText:@"公告标题, 公告标题..." font:kFontSize_26];
        [self.contentView addSubview:_contentLabel = label];
    }
    return _contentLabel;
}
- (UIImageView *)images{
    if (!_images) {
        UIImageView *image = [UIImageView createImageViewWithName:@"img_banner"];
        image.contentMode = UIViewContentModeScaleToFill;
        image.clipsToBounds = YES;
        [self.contentView addSubview:_images = image];
    }
    return _images;
}
- (UIButton *)leftButton{
    if (!_leftButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"" target:self action:@selector(button:)];
        button.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:_leftButton = button];
    }
    return _leftButton;
}
- (UIButton *)rightButton{
    if (!_rightButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"" target:self action:@selector(button:)];
        button.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:_rightButton = button];
    }
    return _rightButton;
}
@end
